import { Form, Input, Button, NavBar } from "antd-mobile";
import { useNavigate } from "react-router-dom";
import { editmimaAPI } from "../services/user";
import { removeToken } from "../utils/tools";

function Repassword() {
  const nav = useNavigate();
  const back = () => nav(-1);
  return (
    <div>
      <NavBar back="返回" onBack={back}></NavBar>
      <Form
        layout="horizontal"
        footer={
          <Button block type="submit" color="primary" size="large">
            提交
          </Button>
        }
        onFinish={(v) => {
          console.log(v);
          editmimaAPI(v).then((res) => {
            // alert(res.data);
            if (res.success == true) {
              removeToken();
              nav("/login");
            } else {
              alert(res.errorMessage);
            }
          });
        }}
      >
        <Form.Item name="oldPassword" label="旧密码">
          <Input type="password" placeholder="请输入旧密码" />
        </Form.Item>
        <Form.Item label="新密码" name="password">
          <Input type="password" placeholder="请输入新密码"></Input>
        </Form.Item>
      </Form>
    </div>
  );
}

export default Repassword;
